/////////////////////////////////////////////////////
//
//  for animating a scrollTo 
//  para animar el funcion scrollTo
//  
//  @param X : x-coord to scroll to
//  		x-coord donde a mover
//  @param Y : y-coord to scroll to
//  		y-coord donde a mover
//  @param s : number of steps to animate through
//  		quantidad de los pasos 
//  @param ease : equations of transition
//  		IN/OUT/INOUT/LINEAR
//  		defaults to IN
//  		tipos del transicion
//  		EN/FUERA/ENFUERA/LINEAR
//
//  
/////////////////////////////////////////////////////

var inc = 0;
var isNotRunning = true;

//function slipTo(X, Y, s, p, ease) {if(inc == 0){
function slipTo(X, Y, s, p, ease) {if(isNotRunning){

	isNotRunning       = false;
	defaultNumOfSteps  = 15;
	defaultPause       = 1;
	defaultEase        = 'IN';

	inc = 0;
	offsetX = window.pageXOffset || document.body.scrollLeft;
	offsetY = window.pageYOffset || document.body.scrollTop;
       	steps = s || defaultNumOfSteps,
	pause = p || defaultPause,
	xdiff = X - offsetX,
	ydiff = Y - offsetY;

	//uncomment to prevent user scrolling during animation
	//here and below
	//document.body.style.overflow = 'hidden';

	this.easeType = ease || defaultEase;//default to easing in

	this.animan = function(){
	
	 if(inc < steps){
	
	  var percent = this.calcTween();
	  var tmpX = percent*xdiff+offsetX;
	  var tmpY = percent*ydiff+offsetY;
  	  window.scroll(tmpX,tmpY);
 	  inc++;
	  //goog-chrome can not handle this with setInterval
	  //do _not_ use setInterval
	  setTimeout('this.animan()',pause);

	 }else{

	  inc = 0;
	  isNotRunning = true;
	  window.scroll(X,Y);
	  //uncomment when preventing user scrolling
	  //document.body.style.overflow = 'auto';
	  return false;

	 }

	}

	this.calcTween = function(){};

	switch (this.easeType) {

		case 'LINEAR' :

			this.calcTween = function(){
			  return (inc/steps);
			};

			break;

		case 'FUERA' :
		case 'OUT' :
			
			this.calcTween = function(){
			  var percent = (inc/steps);
			  return percent*percent;
			};

			break;

		case 'ENFUERA' :
		case 'INOUT' :
			
			this.calcTween = function(){
			 var percent = (inc/steps);
			 if(percent < .5){
			  return 2*percent*percent;
			 }else{
			  percent = (1-inc/steps);
		  	  percent = .5+(.5-percent*percent);
		          //alert('next section\n\n'+ percent);
			  return percent;

			 }
			};

			break;


		default : // IN

			this.calcTween = function(){
			 var percent = (1-inc/steps);
			 return 1-percent*percent;
			};

	}

	this.animan();


}}


